<?php
session_start();
function mysqlConnect_PHP(){
		include('../config/config.inc.php');	
		$db = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
		$db_select = mysql_select_db($mysql_dbname, $db);	
}

function getDBrow($username, $dbname)
{
	if(empty($username))
		return 0;
	else
	{
		mysqlConnect_PHP();
		$query = "SELECT * FROM ".$dbname." WHERE username='".$username."';";
		$result = mysql_query($query);
		while($res = mysql_fetch_array($result))
		{
			return $res;
		}	
	}
}
$infos=getDBrow($_SESSION['username'], 'accounts');
if($infos['admin'] == 1)
{
	?>
	<head>
		<title>MyBook+</title>
		<link rel="icon" href="../favicon.ico" type="image/x-icon" /> 
		<meta name="description" content="Das beste Social Network der Welt" content="text/html; utf-8"/>
		<style>
			body{
				overflow-y: auto;
			}
			td{
				border-bottom: #a0a0a0 1px solid;
				vertical-align: top;
			}
		</style>
	</head>
	<body width="100%">
	<div style="float: left; height: 50px; width: 100%; background: #303030; margin-bottom: 20px; box-shadow: 0 0 10px 1px #505050; "><a href="./index.php"><img src="./back.png"/ style="float: left; height: 50px; width: 82px; "></a>
		<h1 style="float: left; margin: 6px 0 0 30px; color: #f0f0f0;"> Development - Datenbank Tabellen</h1>
	</div>
	<h2>
	<?php 
		switch($_GET['db'])
			{
				case 1: echo "accounts"; break; 
				case 2: echo "background"; break; 
				case 3: echo "friend_invite"; break; 
				case 4: echo "friends"; break; 
				case 5: echo "message"; break;
				case 6: echo "posts"; break;
				case 7: echo "posts_comments"; break;
				case 8: echo "profile"; break;
				case 9: echo "style"; break;
				
			}
	?>
	</h2>
	<form action="" method="get">
		<select name="db">
			<option value="1" <?php if($_GET['db'] == 1) echo "selected";?>>accounts</option>
			<option value="2" <?php if($_GET['db'] == 2) echo "selected";?>>background</option>
			<option value="3" <?php if($_GET['db'] == 3) echo "selected";?>>friend_invite</option>
			<option value="4" <?php if($_GET['db'] == 4) echo "selected";?>>friends</option>
			<option value="5" <?php if($_GET['db'] == 5) echo "selected";?>>message</option>
			<option value="6" <?php if($_GET['db'] == 6) echo "selected";?>>posts</option>
			<option value="7" <?php if($_GET['db'] == 7) echo "selected";?>>posts_comments</option>
			<option value="8" <?php if($_GET['db'] == 8) echo "selected";?>>profile</option>
			<option value="9" <?php if($_GET['db'] == 9) echo "selected";?>>style</option>
		</select>
		<input type="submit" value="Show">
	</form>
		<?php
			switch($_GET['db'])
			{
				case 1:
					echo '<table width="100%">';
					?>
						<tr>
							<td width="10%"><b>ID</b></td>
							<td width="25%"><b>Username</b></td>
							<td width="25%"><b>Passwort</b></td>
							<td width="30%"><b>Email</b></td>
							<td width="10%"><b>Admin</b></td>
						</tr>
					<?php
					mysqlConnect_PHP();
					$query = "SELECT * FROM accounts ORDER BY id;";
					$result = mysql_query($query);
					while($res = mysql_fetch_array($result))
					{
						echo '<tr>';
						echo '<td width="10%">'.$res['id'].'</td>';
						echo '<td width="25%">'.$res['username'].'</td>';
						echo '<td width="25%">'.$res['password'].'</td>';
						echo '<td width="30%">'.$res['email'].'</td>';
						echo '<td width="10%">'.$res['admin'].'</td>';
						echo '</tr>';
					}
					echo "</table>";
					break;	
					
				case 2:
					echo '<table width="100%">';
					?>
						<tr>
							<td width="50%"><b>userid</b></td>
							<td width="50%"><b>background</b></td>
						</tr>
					<?php
					mysqlConnect_PHP();
					$query = "SELECT * FROM background ORDER BY userid;";
					$result = mysql_query($query);
					while($res = mysql_fetch_array($result))
					{
						echo '<tr>';
						echo '<td width="50%">'.$res['userid'].'</td>';
						echo '<td width="50%">'.$res['background'].'</td>';
						echo '</tr>';
					}
					echo "</table>";
					break;
				
				case 3:
					echo '<table width="100%">';
					?>
						<tr>
							<td width="20%"><b>userid</b></td>
							<td width="40%"><b>friendid</b></td>
							<td width="40%"><b>blocked</b></td>
						</tr>
					<?php
					mysqlConnect_PHP();
					$query = "SELECT * FROM friend_invite;";
					$result = mysql_query($query);
					while($res = mysql_fetch_array($result))
					{
						echo '<tr>';
						echo '<td width="20%">'.$res['userid'].'</td>';
						echo '<td width="40%">'.$res['friendid'].'</td>';
						echo '<td width="40%">'.$res['blocked'].'</td>';
						echo '</tr>';
					}
					echo "</table>";
					break;	
					
				case 4:
					echo '<table width="100%">';
					?>
						<tr>
							<td width="50%"><b>userid</b></td>
							<td width="50%"><b>friendid</b></td>
						</tr>
					<?php
					mysqlConnect_PHP();
					$query = "SELECT * FROM friends;";
					$result = mysql_query($query);
					while($res = mysql_fetch_array($result))
					{
						echo '<tr>';
						echo '<td width="50%">'.$res['userid'].'</td>';
						echo '<td width="50%">'.$res['friendid'].'</td>';
						echo '</tr>';
					}
					echo "</table>";
					break;
				
				case 5:
					echo '<table width="100%">';
					?>
						<tr>
							<td width="10%"><b>ID</b></td>
							<td width="10%"><b>userid</b></td>
							<td width="10%"><b>friendid</b></td>
							<td width="10%"><b>date</b></td>
							<td width="10%"><b>time</b></td>
							<td width="10%"><b>unread</b></td>
							<td width="40%"><b>message</b></td>
						</tr>
					<?php
					mysqlConnect_PHP();
					$query = "SELECT * FROM message ORDER BY id;";
					$result = mysql_query($query);
					while($res = mysql_fetch_array($result))
					{
						echo '<tr>';
						echo '<td width="10%">'.$res['id'].'</td>';
						echo '<td width="10%">'.$res['userid'].'</td>';
						echo '<td width="10%">'.$res['friendid'].'</td>';
						echo '<td width="10%">'.$res['date'].'</td>';
						echo '<td width="10%">'.$res['time'].'</td>';
						echo '<td width="10%">'.$res['unread'].'</td>';
						echo '<td width="40%">'.stripslashes(nl2br(htmlspecialchars($res['message']))).'</td>';
						echo '</tr>';
					}
					echo "</table>";
					break;	
					
				case 6:
					echo '<table width="100%">';
					?>
						<tr>
							<td width="10%"><b>ID</b></td>
							<td width="10%"><b>userid</b></td>
							<td width="10%"><b>wall</b></td>
							<td width="40%"><b>post</b></td>
							<td width="10%"><b>public</b></td>
							<td width="10%"><b>date</b></td>
							<td width="10%"><b>time</b></td>
						</tr>
					<?php
					mysqlConnect_PHP();
					$query = "SELECT * FROM posts ORDER BY id;";
					$result = mysql_query($query);
					while($res = mysql_fetch_array($result))
					{
						echo '<tr>';
						echo '<td width="10%">'.$res['id'].'</td>';
						echo '<td width="10%">'.$res['userid'].'</td>';
						echo '<td width="10%">'.$res['wall'].'</td>';
						echo '<td width="40%">'.stripslashes(nl2br(htmlspecialchars($res['post']))).'</td>';
						echo '<td width="10%">'.$res['public'].'</td>';
						echo '<td width="10%">'.$res['date'].'</td>';
						echo '<td width="10%">'.$res['time'].'</td>';
						echo '</tr>';
					}
					echo "</table>";
					break;	
					
				case 7:
					echo '<table width="100%">';
					?>
						<tr>
							<td width="10%"><b>ID</b></td>
							<td width="10%"><b>postid</b></td>
							<td width="10%"><b>userid</b></td>
							<td width="50%"><b>comment</b></td>
							<td width="10%"><b>date</b></td>
							<td width="10%"><b>time</b></td>
						</tr>
					<?php
					mysqlConnect_PHP();
					$query = "SELECT * FROM posts_comments ORDER BY id;";
					$result = mysql_query($query);
					while($res = mysql_fetch_array($result))
					{
						echo '<tr>';
						echo '<td width="10%">'.$res['id'].'</td>';
						echo '<td width="10%">'.$res['postid'].'</td>';
						echo '<td width="10%">'.$res['userid'].'</td>';
						echo '<td width="50%">'.stripslashes(nl2br(htmlspecialchars($res['comment']))).'</td>';
						echo '<td width="10%">'.$res['date'].'</td>';
						echo '<td width="10%">'.$res['time'].'</td>';
						echo '</tr>';
					}
					echo "</table>";
					break;
					
				case 8:
					echo '<table width="100%">';
					?>
						<tr>
							<td width="10%"><b>userid</b></td>
							<td width="15%"><b>username</b></td>
							<td width="15%"><b>vorname</b></td>
							<td width="15%"><b>nachname</b></td>
							<td width="30%"><b>about</b></td>
							<td width="15%"><b>profilepic</b></td>
						</tr>
					<?php
					mysqlConnect_PHP();
					$query = "SELECT * FROM profile ORDER BY userid;";
					$result = mysql_query($query);
					while($res = mysql_fetch_array($result))
					{
						echo '<tr>';
						echo '<td width="10%">'.$res['userid'].'</td>';
						echo '<td width="15%">'.$res['username'].'</td>';
						echo '<td width="15%">'.$res['vorname'].'</td>';
						echo '<td width="15%">'.$res['nachname'].'</td>';
						echo '<td width="30%">'.stripslashes(nl2br(htmlspecialchars($res['about']))).'</td>';
						echo '<td width="15%">'.$res['profilepic'].'</td>';
						echo '</tr>';
					}
					echo "</table>";
					break;
				
				case 9:
					echo '<table width="100%">';
					?>
						<tr>
							<td width="50%"><b>userid</b></td>
							<td width="50%"><b>style</b></td>
						</tr>
					<?php
					mysqlConnect_PHP();
					$query = "SELECT * FROM style ORDER BY userid;";
					$result = mysql_query($query);
					while($res = mysql_fetch_array($result))
					{
						echo '<tr>';
						echo '<td width="50%">'.$res['userid'].'</td>';
						echo '<td width="50%">'.$res['style'].'</td>';
						echo '</tr>';
					}
					echo "</table>";
					break;
			}
		?>
	</body>
<?php
}
?>